﻿using System;

namespace homework02_2
{
    class Sizeof
    {
        static void Main1()
        {
            Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}", "Type", "Size (Bytes)", "Min Value", "Max Value");
            Console.WriteLine(new string('-', 80));

            PrintTypeInfo<sbyte>("sbyte");
            PrintTypeInfo<byte>("byte");
            PrintTypeInfo<short>("short");
            PrintTypeInfo<ushort>("ushort");
            PrintTypeInfo<int>("int");
            PrintTypeInfo<uint>("uint");
            PrintTypeInfo<long>("long");
            PrintTypeInfo<ulong>("ulong");
            PrintTypeInfo<float>("float");
            PrintTypeInfo<double>("double");
            PrintTypeInfo<decimal>("decimal");
        }

        static void PrintTypeInfo<T>(string typeName) where T : struct
        {
            Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}",
                typeName,
                System.Runtime.InteropServices.Marshal.SizeOf(default(T)),
                typeof(T).GetField("MinValue").GetValue(null),
                typeof(T).GetField("MaxValue").GetValue(null));
        }
    }
}

